﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace ConsoleApp
{

    public class BitConvert
    {

        
        static void Main1(string[] args)
        {
            byte[] bigEndianBytes = { 0x12, 0x34, 0x56, 0x78 };

            // 反转字节数组以转换为小端序
            byte[] littleEndianBytes = new byte[bigEndianBytes.Length];
            Array.Copy(bigEndianBytes, littleEndianBytes, bigEndianBytes.Length);
            Array.Reverse(littleEndianBytes);

            // 输出小端序字节数组
            Console.Write($"小端序字节数组: {littleEndianBytes}");
            foreach (byte b in littleEndianBytes)
            {
                Console.Write($"{b:X2} ");
            }
            Console.WriteLine();
        }
        static void Main2(string[] args) 
        {
            var engine = new Engine();
            var car = new Car(engine);
            car.Run(3);
            Console.WriteLine(car.Speed);
        }
        class Engine
        {
            public int RPM { get; set; }
            public void Work(int gas) 
            {
                RPM = gas*1000;
            }
        }
        class Car
        {
            public int Speed { get; set; }

            Engine _engine { get; set; }
            public Car(Engine engine) 
            { 
                _engine = engine;
            } 
            public void Run(int gas)
            {
                _engine.Work(gas);
                Speed = _engine.RPM/100;
            }
        }
    }


    public class  Take
    {
        //Skip(1).Take(5)，跳过第一个,拿之后的5个2-6
        static void Main(string[] args)
        {
            byte[] bytes = new byte[] { 0x53,0x54,0x41,0x52 ,0x54, 0x00, 0x0d, 0xaa, 0x00 ,0x00 ,0x00 ,0x00, 0x15, 0x17 ,0x00 ,0x00, 0x00, 0x00, 0x00 ,0x00 ,0x00 ,
                0x01 ,0x00 ,0x00, 0x00 ,0x00 ,0xff ,0xff ,0xff ,0x00 ,0x00 ,0x00 ,0x3e ,0xb2 ,0x00 ,0xe1 ,0xc0 ,0x00 ,0x93 ,0xa3, 0x00 ,0x93 ,0x09 ,0x01 ,0x45 ,0x4e ,0x44 };
            var startStr = BitConverter.ToString(bytes.Take(5).ToArray()).Replace("-"," ");
            var startByte = bytes.Take(5).ToArray();
            var bytesByte = bytes.ToArray();
            var FirstData = bytes.Skip(21).Take(18).ToArray();
            var sn = FirstData.Skip(2).Take(8).ToArray();
            var firmware = FirstData.Skip(10).Take(8).ToArray();
            Console.WriteLine(BitConverter.ToString(FirstData).Replace("-"," "));
            Console.WriteLine(BitConverter.ToString(sn).Replace("-"," "));
            Console.WriteLine(BitConverter.ToString(firmware).Replace("-"," "));
            Console.WriteLine("==============================================");
            Console.WriteLine(Encoding.ASCII.GetString(startByte));
            Console.WriteLine(Encoding.ASCII.GetString(bytesByte));
        }
    }
}
